using System;
using System.Collections.Generic;
using NUnit.Framework;
using Rhino.Mocks;
using StrategicDataSystems.Cloud.Monitoring.Configuration;
using StrategicDataSystems.Cloud.Monitoring.HostedServices;
using StrategicDataSystems.Cloud.Monitoring.UI.Services;
using StrategicDataSystems.Cloud.Monitoring.UI.ViewModels;

namespace StrategicDataSystems.Cloud.Monitoring.Tests.Given_A_SysTrayViewModel
{
    [TestFixture]
    public class When_No_Deployments_Are_Found
    {
        [Test]
        public void Should_Set_SubscriptionHasCurrentDeployment_Flag_To_False()
        {
            var stubHostedServiceGateway = MockRepository.GenerateStub<IHostedServiceManagement>();
            var stubNotificationService = MockRepository.GenerateStub<INotificationService>();
            var stubNetPresenceService = MockRepository.GenerateStub<INetPresenceService>();
            var mockTimerService = MockRepository.GenerateMock<ITimerService>();

            var fakeHostedServices = new List<HostedService>() { 
		                    new HostedService("service1", new Uri("http://management.net"), 
		                        new List<Deployment> ()) };

            Settings settings = new Settings();

            stubHostedServiceGateway.Stub(
                x => x.GetHostedServicesForSubscription(settings.SubscriptionId, settings.CertificateThumbprint))
                .Return(fakeHostedServices);

            SysTrayViewModel viewModel = new SysTrayViewModel(stubHostedServiceGateway, settings, stubNotificationService, mockTimerService, stubNetPresenceService);

            Assert.IsFalse(viewModel.SubscriptionHasCurrentDeployments, "Should not have indicated a deployment.");
        }

        [Test]
        public void Should_Return_Empty_Collection_For_ActiveDeployments()
        {
            var stubHostedServiceGateway = MockRepository.GenerateStub<IHostedServiceManagement>();
            var stubNotificationService = MockRepository.GenerateStub<INotificationService>();
            var stubNetPresenceService = MockRepository.GenerateStub<INetPresenceService>();
            var mockTimerService = MockRepository.GenerateMock<ITimerService>();

            var fakeHostedServices = new List<HostedService>();

            Settings settings = new Settings();

            stubHostedServiceGateway.Stub(
                x => x.GetHostedServicesForSubscription(settings.SubscriptionId, settings.CertificateThumbprint))
                .Return(fakeHostedServices);

            SysTrayViewModel viewModel = new SysTrayViewModel(stubHostedServiceGateway, settings, stubNotificationService, mockTimerService, stubNetPresenceService);

            Assert.IsTrue(viewModel.ActiveDeployments.Count == 0);
        }


        [Test]
        public void Should_Not_NotifyUser_Of_Deployments()
        {
            var stubHostedServiceGateway = MockRepository.GenerateStub<IHostedServiceManagement>();
            var mockNotificationService = MockRepository.GenerateMock<INotificationService>();
            var stubNetPresenceService = MockRepository.GenerateStub<INetPresenceService>();
            var mockTimerService = MockRepository.GenerateMock<ITimerService>();

            var fakeHostedServices = new List<HostedService>() { 
		                    new HostedService("service1", new Uri("http://management.net"), 
		                        new List<Deployment> ()) };

            Settings settings = new Settings();

            stubHostedServiceGateway.Stub(
                x => x.GetHostedServicesForSubscription(settings.SubscriptionId, settings.CertificateThumbprint))
                .Return(fakeHostedServices);

            SysTrayViewModel viewModel = new SysTrayViewModel(stubHostedServiceGateway, settings, mockNotificationService, mockTimerService, stubNetPresenceService);

            mockNotificationService.AssertWasNotCalled(x => x.NotifyUserOfActiveDeployment(1));
        }
    }
}
